//签名交易

//var bitcore = require('bitcore-lib')
var bitcoin = require('bitcoinjs-lib')

var network = bitcoin.networks.testnet
//notice input的交易id  必须用input对应地址的私钥签名  
   var wif = 'cSP3R6aSXSRCwGfHGAjwtqKGLRQeKYR23Ga5AfsEXNz4MBaKXiiY'          //myEguG6rkneMk3AHfZyDfHQvFc6xG9wdCH
   var alice = bitcoin.ECPair.fromWIF(wif,network)
    var txb = new bitcoin.TransactionBuilder(network)

    txb.setVersion(1)
    txb.addInput('855b80ef200bbab286f43a1ce5ea7cf560ee3947ad91e656541d8c23cebdc5ab', 0) 
    txb.addOutput('mxsQmW8AiifZfGpRuh5ZRkonsjo8eWaUAp', 0.5*100000000)//转出地址
    txb.addOutput('myEguG6rkneMk3AHfZyDfHQvFc6xG9wdCH', 0.049*100000000)//找零地址  咱们设为自己
    

    txb.sign(0, alice)
    console.log(txb.build().toHex())

    //TransactionBuilder.prototype.sign




//0100000001933c0ffbd3acafab39cd99431bcb1ab42ca1e6fb62bb4987047a332ece6e36e1000000006b483045022100e7b81320c9b8710dd3de1ccf94b650b0834973829b25a3c3f99bde3a9c2e4c65022003dcc496af0ea7890b4833cddb4ebd002c786dbae86fcedc8d502c118a37887e0121023db042ba4d0d19895c66ce82959f36b50b7d0ad3b7700d93695e43767b5197deffffffff02404b4c00000000001976a914be588e6b2450154be3153428bd597344e3c6b54388ac70c9fa02000000001976a9148b444b289eb294059ec104118d9dc292eee8e40f88ac00000000



